﻿using System;
using System.Collections.Generic;
using System.Threading;
using Hongsh.Pay.Client.Proxy.Http;
using MapleLeaf.Pay.Pay;
using MapleLeaf.Pay.Trade;

namespace Hongsh.Pay.Client.Proxy.Handlers {
    // Token: 0x0200007E RID: 126
    public static class HongshPayProxy {
        // Token: 0x06000480 RID: 1152 RVA: 0x00004B7E File Offset: 0x00002D7E
        public static void AddHongshPayProxyHandler(this HttpServer svr) {
            svr.RouterList.Add("GET/", new HttpContextActionDelegate(Home));
        }

        // Token: 0x06000481 RID: 1153 RVA: 0x00004B9C File Offset: 0x00002D9C
        private static void Home(HttpContext ctx) {
            ctx.Result = new HttpTextResult("HongshPayProxy", "text/plain");
        }

        // Token: 0x06000482 RID: 1154 RVA: 0x0000FF80 File Offset: 0x0000E180
        private static void AccecptReqeust<T>(this HttpContext ctx, T req) where T : TradeRequest {
            req.ClientIP = ctx.Connection.RemoteEndPoint.Address.ToString();
            req.ClientName = ctx.Action.Method.DeclaringType.Name;
            string key = req.ClientIP + " " + typeof(T).Name;
            DateTime d;
            if (TradeApiRecord.TryGetValue(key, out d)) {
                int num = (int)(3000.0 - (DateTime.Now - d).TotalMilliseconds);
                if (num > 0) {
                    Thread.Sleep(num);
                }
            }
            TradeApiRecord[key] = DateTime.Now;
        }

        // Token: 0x06000483 RID: 1155 RVA: 0x0001003C File Offset: 0x0000E23C
        public static HongshPayTrade Execute(this HttpContext ctx, TradeAuthPaymentRequest req) {
            ctx.AccecptReqeust(req);
            return (ctx.Server.Context["HongshPayTradeManager"] as HongshPayTradeManager).Execute(req);
        }

        // Token: 0x06000484 RID: 1156 RVA: 0x00010074 File Offset: 0x0000E274
        public static HongshPayTrade Execute(this HttpContext ctx, TradePaymentQueryRequest req) {
            ctx.AccecptReqeust(req);
            return (ctx.Server.Context["HongshPayTradeManager"] as HongshPayTradeManager).Execute(req);
        }

        // Token: 0x06000485 RID: 1157 RVA: 0x000100AC File Offset: 0x0000E2AC
        public static HongshPayTrade Execute(this HttpContext ctx, TradeRefundQueryRequest req) {
            ctx.AccecptReqeust(req);
            return (ctx.Server.Context["HongshPayTradeManager"] as HongshPayTradeManager).Execute(req);
        }

        // Token: 0x06000486 RID: 1158 RVA: 0x000100E4 File Offset: 0x0000E2E4
        public static HongshPayTrade Execute(this HttpContext ctx, TradeRefundRequest req) {
            ctx.AccecptReqeust(req);
            return (ctx.Server.Context["HongshPayTradeManager"] as HongshPayTradeManager).Execute(req);
        }

        // Token: 0x06000487 RID: 1159 RVA: 0x0001011C File Offset: 0x0000E31C
        public static HongshPayTrade Execute(this HttpContext ctx, TradeCloseRequest req) {
            ctx.AccecptReqeust(req);
            return (ctx.Server.Context["HongshPayTradeManager"] as HongshPayTradeManager).Execute(req);
        }

        // Token: 0x06000488 RID: 1160 RVA: 0x00004BB3 File Offset: 0x00002DB3
        static HongshPayProxy() {
            //Class15.cwcZ3SWztHroi();
            TradeApiRecord = new Dictionary<string, DateTime>();
        }

        // Token: 0x040001F4 RID: 500
        private static readonly Dictionary<string, DateTime> TradeApiRecord;
    }
}
